package com.shntec.bp.common;

import com.shntec.bp.util.ShntecConfigManager;
import com.shntec.bp.util.ShntecLogger;

public abstract class ShntecBaseAction {

	protected int actionCode = JSONMessageConstant.ACTION_CODE_UNKNOWN_ACTION;
	
	protected String actionName = null;
	
	protected String actionDescription = null;
	
	protected boolean needAuthenticationCheck = false;
	
	public abstract ResponseMessageGenerator handleAction( RequestMessageParser parser );

	public int getActionCode() {
		
		return actionCode;
		
	}
	
	public String getActionName() {
		
		return actionName;
		
	}
	
	public String getActionDescription () {
		
		return actionDescription;
		
	}
	
	public ResponseMessageGenerator execute(RequestMessageParser parser) {
		
		ResponseMessageGenerator generator = new ResponseMessageGenerator();
		
		ShntecLogger.logger.debug("Enter action execution, action name:" + actionName);

//		if (ShntecConfigManager.enableAuthenticationCheck 
//				&& needAuthenticationCheck) {
//			ShntecLogger.logger.debug("Start to check action authentication.");
//			// Check authentication token
//			String authToken = parser.getActionAuthentication();
//			if (authToken == null) {
//				return generator.toError(parser, XMMServerErrorCode.XMMSERVER_ERROR_CODE_USER_NOT_LOGIN);
//			}
//			else {
//				XMMServerSessionManager sessionManager = XMMServerSessionManager.getInstance();
//				String clientIP = parser.getRequest().getRemoteAddr();
//				if (!sessionManager.checkAuthToken(authToken, clientIP, null)) {
//					return generator.toError(parser, XMMServerErrorCode.XMMSERVER_ERROR_CODE_AUTHENTICATION_ERROR);			
//				}
//			}
//		}

		return handleAction(parser);
	}
}
